home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
FFT and Complex Numbers Library
/
FFTLibrary.sit
/
FFT library ƒ
/
FFT.cp
< prev
next >
Wrap
Text File
|
1995-01-15
|
2KB
|
87 lines
//
// File: FFT.cp
// Copyright ⌐1994-1995 James Wilson
// All rights reserved.
//
// Revisions:
// 8-2-94: Took out the constant multiplication part of arg and
// placed into halfArg. halfArg is multiplied by p to get arg.
// Removed the "f" suffix from 1.0 on line 34. Replaced the temp
// variable with the slightly more descriptive name "swap."
// 7-29-94: Replaced all instances of floating-point division with
// multiplication by reciprocals, since multiplication is much
// faster on PowerPC.
//
// This is the implementation file for the Fast Fourier transform (FFT)
// algorithm. I have not made an extensive effort to comment every
// line of code, as that would lengthen this document by several more
// pages. I assume that the reader or user of this code has a decent
// understanding of both the DFT and the FFT.
#ifndef __FFT__
#include "FFT.h"
#endif
void FFT(const long n, const long nu, ComplexArray spectrumOut)
{
long n2, nu1, i, k, p, x, tempIndex, denom;
double arg, reciprocalN, halfArg;
Complex exponent, swap;
// Initalization process.
x = 1L;
n2 = n / 2L;
nu1 = nu - 1L;
k = 0L;
reciprocalN = 1.0 / n;
halfArg = twoPi * reciprocalN;
// First step: calculate the Fourier transforms of the input values.
// The results are scrambled and are unscrambled at the end (see
// below).
while(x <= nu)
{
for(i = 1L; i <= n2; i++, k++)
{
denom = LongPower(2L, nu1);
p = BitReverse(k/denom, nu);
arg = halfArg * p;
exponent.Real() = cos(arg);
exponent.Imag() = -sin(arg);
tempIndex = k + n2;
swap = exponent * spectrumOut[tempIndex];
spectrumOut[tempIndex] = spectrumOut[k] - swap;
spectrumOut[k] += swap;
}
k += n2;
if(k >= n)
{
x++;
n2 /= 2L;
nu1--;
k = 0L;
}
}
// Last step: unscramble the results. This is done by swapping the
// values in spectrumOut[k] with spectrumOut[BitReverse(k, nu)].
while(k < n)
{
i = BitReverse(k, nu);
if(i > k)
{
swap = spectrumOut[k];
spectrumOut[k] = spectrumOut[i];
spectrumOut[i] = swap;
}
k++;
}
}